//解答题操作接口，负责试题的渲染，做题，显示答案等。


//-------------------------调用android接口-------------------------------
//页面加载完毕事件
function onLoad() {
    console.log('onLoad');
    window.location.href = 'hybird://method/onLoad';
}

function afterSetQuestion(result) {
	console.log('afterSetQuestion');
	window.location.href = 'hybird://method/afterSetQuestion?result=' + result;
}

/**
 * 跳转到下一题
 */
function next() {
    console.log('next');
    window.location.href = 'hybird://method/next';
}

/**
 * 跳转到上一题
 */
function preview() {
    console.log('preview');
    window.location.href = 'hybird://method/preview';
}

/**
 * 跳转到答题卡
 */
function showAnswerSheet() {
    console.log('showAnswerSheet');
    window.location.href = 'hybird://method/showAnswerSheet';
}

function saveErrorReason(ids) {
    console.log('saveErrorReason:'+ids);
    window.location.href = 'hybird://method/saveErrorReason?ids=' + optionCode;
}

function saveLevelAttained(ids) {
    console.log('saveErrorReason:'+ids);
    window.location.href = 'hybird://method/saveErrorReason?ids=' + optionCode;
}

//-------------------------webview对外接口-------------------------------

/**
 * 显示答案
 */
function showAnswer(flag) {
    var panel = $('.answer');
    if(typeof flag === 'undefined') {
        if(panel.is(':hidden')) {
            flag = true;
        }else {
            flag = false;
        }
    }
    if(flag) {
        panel.show();
    }else {
        panel.hide();
    }
}


//-------------------------页面操作-------------------------------

var page = {
    MODE_READ: "NO", //浏览模式
    MODE_WRITE: "YES" //做题模式
};

/**
 * 添加错误原因及掌握程度单击事件
 */
function addSummarySelectClickListener() {
	var singleMode = $("#singleMode").val();
	$('.errorItem').change(function() {
        var id = $(this).attr("id");
        var value = $(this).val();
        if (id === 'errorReason') {
            edit('errorReason', value);
        } else if (id === 'levelAttained') {
            edit('levelAttained', value);
        }
    });
}


function addPageBtnClickListener() {
    $('.pageBar .btn').on('click', function() {
        var id = $(this).attr("id");
        if(id ==='btn_preview') {
            preview();
        }else if(id ==='btn_next') {
            next();
        }else if(id ==='btn_answersheet') {
            showAnswerSheet();
        }
    });
}

window.onload = function() {
    addPageBtnClickListener();
    addSummarySelectClickListener()
    onLoad();
};
